package com.tsingteng.cosfun.callback;


import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.tsingteng.cosfun.common.Navigate;
import com.tsingteng.cosfun.crashUtils.utils.LogUtil;
import com.tsingteng.cosfun.utils.LogonUtils;
import com.tsingteng.cosfun.utils.SPUtils;
import com.tsingteng.cosfun.utils.ShareUtils;
import com.tsingteng.cosfun.utils.StringUtils;
import com.umeng.socialize.bean.SHARE_MEDIA;

import org.json.JSONStringer;

/**
 * app 与js 相互调用
 * <p>
 * author zht
 */
public class ActivityJavascriptInterface {

    private Activity mContext;

    public ActivityJavascriptInterface(Activity context) {
        this.mContext = context;
    }

    @JavascriptInterface
    public void getVideoList(int position, String json) {
        if (StringUtils.isFastDoubleClick(500)){
            return;
        }
        if (!TextUtils.isEmpty(json)) {
            Navigate.gotoJoin(mContext, json, position);
        }
    }

    @JavascriptInterface
    public void getDetail(long id) {

    }

    @JavascriptInterface
    public void back() {
        mContext.finish();
    }

    @JavascriptInterface
    public String isLogin() {
        if (LogonUtils.chckLogon(mContext,false,3)){
            String cookie = SPUtils.init().getString("cookie");
            if (TextUtils.isEmpty(cookie)) {
                return null;
            }
            return cookie;
        }
        return null;
    }
    @JavascriptInterface
    public String getProfileId() {
        if (LogonUtils.getIsLogin()) {
            return SPUtils.init().getString("cookie");
        } else {
            return null;
        }
    }
    @JavascriptInterface
    public void receiveAddress(){
        Navigate.gotoProfileAdress(mContext);
    }

    @JavascriptInterface
    public void shareWithInfo(String url,String title,String content,String imagUrl,String info) {
        if (TextUtils .isEmpty(url)){
            return;
        }
        if (TextUtils.isEmpty(title)){
            return;
        }
        if (TextUtils.isEmpty(content)){
            return;
        }
        if (TextUtils.isEmpty(info)){
            return;
        }
        switch (info) {
            case "0":
                ShareUtils.getIntance().shareLink(mContext, SHARE_MEDIA.WEIXIN,url,imagUrl,title,content);
                break;
            case "1":
                ShareUtils.getIntance().shareLink(mContext, SHARE_MEDIA.WEIXIN_CIRCLE,url,imagUrl,title,content);
                break;
            case "2":
                ShareUtils.getIntance().shareLink(mContext, SHARE_MEDIA.QQ,url,imagUrl,title,content);
                break;
            case "3":
                ShareUtils.getIntance().shareLink(mContext, SHARE_MEDIA.QZONE,url,imagUrl,title,content);
                break;
            case "4":
                ShareUtils.getIntance().shareLink(mContext, SHARE_MEDIA.SINA,url,imagUrl,title,content);
                break;
        }
    }
    @JavascriptInterface
    public void sunAward(long activityId){
        if (StringUtils.isFastDoubleClick(500)){
            return;
        }
        Navigate.gotoSunActivity(mContext,activityId);
    }
//    @JavascriptInterface
//    public void goToUrl(String url){
//        LogUtil.d("dddd",url);
//    }
    @JavascriptInterface
    public void getFoundList(int position, int id, String sortType, int page_no, int page_size,String list) {
        Navigate.gotoJSPlay(mContext,position,id,sortType,page_no,page_size,list);
    }

}
